<template>
<!-- 新闻详情页 -->
    <div class="newsinfo-container"> 
        <!-- 新闻标题 -->
        <h3 class="title">{{ newsinfo.title }}</h3>
        <!-- 新闻子标题 -->
        <div class="subtitle">
            <span>发表时间：{{ newsinfo.add_time | dateFormat }}</span>
            <span>点击：{{ newsinfo.click }}次</span>
        </div>
        <hr>
        <!-- 内容 -->
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 发表评论 -->
        <comment-box :id='this.id'></comment-box>
    </div>
</template>
<script>
import { Toast} from 'mint-ui';
import comment from '../subComponents/Comment.vue';
export default {
    data(){
        return {
            id:this.$route.params.id,//获取新闻的id
            newsinfo:{}//新闻对象
        }
    },
    created(){
        this.getNewsInfo();
    },
    methods:{
        getNewsInfo(){//获取新闻详情
            this.$http.get('getnews/'+this.id).then(result=>{
                console.log(result.body);
                if(result.body.status === 0){
                    this.newsinfo = result.body.data[0];
                }else{
                    Toast('获取新闻详情失败');
                }
            })
        }
    },
    components:{
        'comment-box':comment
    }
}
</script>
<style lang="scss" >
.newsinfo-container{
    padding: 0 5px;
    .title{
        color:red;
        font-size: 14px;
        text-align: center;
        margin: 15px;
    }
    .subtitle{
        color:#226aff;
        font-size: 13px;
        display: flex;
        justify-content: space-between;
    }
    .content{
        img{
            width: 100%;
        }
    }
}
</style>
